#include <iostream>
using namespace std;

//
struct Teacher
{
        char name[64];
        int age;
};

//在被调用函数 获取资源
int getTeacher(Teacher **p){
        Teacher *tmp = NULL;

        if(p == NULL){
                return -1;
        }

        tmp = (Teacher *)malloc(sizeof(Teacher));
        if(tmp == NULL){
                return -2;
        }

        tmp->age = 33;

        *p = tmp; 
}

void FreeTeacher(Teacher *p){
        if(p == NULL){
                return ;
        }
        free(p);
}

//指针的引用 作函数参数
int getTeacher2(Teacher* &myp){
        //给myp赋值相当于给main中t1赋值
        myp = (Teacher *)malloc(sizeof(Teacher));
        if(myp == NULL){
                return -1;
        }
        myp->age = 36;
}

int main(int argc, char const *argv[]){
        Teacher *t1 = NULL;

        //1 c语言的二级指针
        getTeacher(&t1);
        cout<<"age: "<< t1->age<<endl;
        FreeTeacher(t1);

        //2 c++中的引用 (指针的引用)
        getTeacher2(t1);
        cout<<"age: "<<t1->age<<endl;
        FreeTeacher(t1);

        return 0;
}